var express=  require("express");
var app=express();
var http = require("http").createServer(app);
var sock = require("socket.io")(http);
function readFile(path){
	var p = new Promise(function(resolve, reject){
		var fs =require("fs");
		fs.readFile(path, function(err, data){
			if(err){
				reject(err);
			}else{
				resolve(data);
			}
		});
	});

	return p;
}
sock.on("connection", function(connection){
	connection.on("message", function(data){

		console.log("Hey");
		sock.emit("reply", "yo!");
	});
});

app.use("/js", express.static("js"));
app.get("/", function(req, res){
	readFile("/pub/VoteD/page.html")
		.then(function(data){

			console.log(data);
			res.end(data.toString());
		})
		.catch(function(e){
			console.log(e);
		});
});

http.listen(9999);
